package fr.web325.servlet.admin.notice;

import fr.web325.bean.Notice;
import fr.web325.dao.NoticeDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/shop/modifyNotice2")
public class ModifyNotice2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取表单数据
        String n_id = req.getParameter("id");
        String title = req.getParameter("title");
        String details = req.getParameter("details");
        String n_time = req.getParameter("n_time");
        Notice notice = new Notice(1, title, details, n_time);
        try {
            if (n_id.equals("")) {
                notice.setN_id(0);
                // 调用新增
                if (new NoticeDao().addNotice(notice)) {
                    // 重定向
                    resp.sendRedirect("admin/notice");
                }
            } else {
                if (new NoticeDao().editNotice(notice)) {
                    // 重定向
                    resp.sendRedirect("admin/notice");
                }
            }
        }catch (SQLException e){
            e.printStackTrace();
        }
    }
}
